﻿using UnityEngine;
using System.Collections;

/// <summary>
/// Script that's run when the game starts.
/// </summary>
public class GameStarted : MonoBehaviour {

	public bool GameHasStarted = false;
	public TextMesh TapToPlayMesh;
	public TextMesh TapToPlayShadowMesh;
	public float DeltaHideText = 1f;
	public Transform Columns;

	Color textStartColor;
	Color shadowStartColor;

	// Use this for initialization
	void Start () {
		textStartColor = TapToPlayMesh.color;
		shadowStartColor = TapToPlayShadowMesh.color;
		this.RandomizeColumns();
	}

	/// <summary>
	/// Fades out the "Click to Play" text.
	/// </summary>
	// Update is called once per frame
	void Update () {
		if (GameHasStarted && DeltaHideText > 0f) {
			DeltaHideText -= Time.deltaTime;
			TapToPlayMesh.color = Color.Lerp(textStartColor, new Color(1f,1f,1f,0f), 1f - DeltaHideText);
			TapToPlayShadowMesh.color = Color.Lerp(shadowStartColor, new Color(1f,1f,1f,0f), 1f - DeltaHideText);
		}
	}

	/// <summary>
	/// Randomize the heights of all of the columns you move through.
	/// </summary>
	void RandomizeColumns() {
		for (int z=0;z<this.Columns.childCount;z++) {
			float newValue = UnityEngine.Random.Range(5.9f,9.5f);
			Transform child = this.Columns.GetChild(z);
			Vector3 vec = child.transform.localPosition;
			vec.y = newValue;
			child.transform.localPosition = vec;
		}
	}
}
